package com.soul.server.controller;

import com.soul.model.mongo.Movement;
import com.soul.model.vo.PageResult;
import com.soul.server.server.CommentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author mdoya
 * @version 1.0
 * @description: 圈子 - 评论
 */
@Slf4j
@RestController
@RequestMapping("/comments")
public class CommentController {

    @Autowired
    private CommentService commentService;

    /**
     *  圈子 - 评论列表
     * @param movementId 动态id
     * @param page 每页码数
     * @param pagesize 每页条数
     * @return PageResult<Movement>
     */
    @GetMapping
    public ResponseEntity findComment(String movementId, @RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10") Long pagesize){
        return ResponseEntity.ok(commentService.findComment(movementId,page,pagesize));
    }

    /**
     *  圈子 - 新增评论
     * @param params 对象
     * @return null
     */
    @PostMapping
    public ResponseEntity addComment(@RequestBody Map<String,String> params){
        commentService.addComment(params.get("movementId"),params.get("comment"));
        return ResponseEntity.ok(null);
    }

    /**
     *  评论-点赞
     * @param commentId 评论id
     * @return 点赞数
     */
    @RequestMapping(path = "/{id}/like",method = RequestMethod.GET)
    public ResponseEntity commentLike(@PathVariable("id") String commentId){
        return ResponseEntity.ok(commentService.commentLike(commentId));
    }

    /**
     *  评论-取消点赞
     * @param commentId 评论id
     * @return 点赞数
     */
    @RequestMapping(path = "/{id}/dislike",method = RequestMethod.GET)
    public ResponseEntity commentDislike(@PathVariable("id") String commentId){
        return ResponseEntity.ok(commentService.commentDislike(commentId));
    }
}
